/*
 * Copyright (c) 2013. mCruncher Sdn Bhd, Cyberjaya, Malaysia.
 * All rights reserved.
 */

package com.mcruncher.properties.converter;

import java.io.File;

/**
 * @author Arunachalam
 * @since 1.0
 */
public class Main
{
    public static void main(String[] args)
    {
        if (args.length >= 1) {
            File file = new File(args[0]);
            if (file.isFile()) {
                if (FileConverterUtils.getFileNameExtension(args[0]).equalsIgnoreCase(FileConverterUtils.PROPERTY_EXTENSION)) {
                    FileConverterUtils.convertToXmlFile(file, getLocale(args));
                    System.out.println("Converted successfully.");
                } else if (FileConverterUtils.getFileNameExtension(args[0]).equalsIgnoreCase(FileConverterUtils.XML_EXTENSION)) {
                    FileConverterUtils.convertToPropertyFile(file, getLocale(args));
                    System.out.println("Converted successfully.");
                } else {
                    System.out.println(FileConverterUtils.getFileNameExtension(file.getName()) + " file not supported.");
                }
            } else {
                System.out.println(file.getName() + " is not a file");
            }

        } else {
            System.out.println("Please give at least one argument as file which may be .properties or .xml");
        }
    }

    static String getLocale(String[] args)
    {
        if (args.length > 1) {
            return "_" + args[1];
        } else {
            return "";
        }
    }
}
